function fld = subsref(ti, S)
% transimg::subsref  - allow read-only access to properties

% check S
if ~isstruct(S) || ...
    isempty(S) || ...
   ~isfield(S, 'type') || ...
   ~isfield(S, 'subs') || ...
   ~strcmp(S(1).type, '.') || ...
   ~any(strcmp(S(1).subs, ...
        {'Background', 'Handle', 'Height', 'IsRendered', 'Layer', 'Rendered', 'Width'}))
    error( ...
        'transimg:InvalidCall', ...
        'Invalid subsref call to transimg object.' ...
    );
end

% global variables for storage
global tiobj ...
       tiobjlup;
   
% check arguments
lup = find(tiobjlup == ti.L);
if numel(lup) ~= 1
    error( ...
        'transimg:ObjectRemoved', ...
        'Object removed from global storage.' ...
    );
end

% first get field
try
    fld = subsref(tiobj(lup), S(1));
    
    % then pass on if needed
    if numel(S) > 1
        fld = subsref(fld, S(2:end));
    end
    
% error handling
catch
    rethrow(lasterror);
end
